﻿@model RoleIndexViewModel
@{
    var x = Html.X();
    Layout = "~/Areas/Platform/Views/Shared/_OrgTreeWindowLayout.cshtml";
    var gridId = "roleGrid"; // + DateTime.Now.Millisecond;
}

@section handlescript{
    <script>
        storeLoad = function (records, options, success) {
            var grid = Ext.getCmp('@gridId');
            var selModel = grid.getSelectionModel();

            var selectData = [];
            for (var i = 0; i < records.data.items.length; i++) {
                var record = records.data.items[i];

                if (record.data.Selected) {
                    selectData.push(record );
                }
            }
            selModel.select(selectData);
        };
        var windowLayoutViewModel = function () {
            var self = this;
            self.saveForm = function(button, event) {

                var grid = button.up('window').down("container[region='center']").down('grid');
                var rows = grid.getSelectionModel().getSelection();
                debugger;
                var output = {
                    userIds: ['@Request["userId"]'],
                    roleIds: []
                };

                Ext.Array.each(rows, function(item, index) { output.push(item.data.Id); });

                $.post('@Url.Action("Relation", "Role")', output,function(result){
                    if (data.errors.length > 0) {
                        Tip("错误", data.errors);

                    } else {

                    }
                });
            };

        }

    </script>
}

@section tabContent{
    @{
        var sharpDataList = x.SharpDataList().GridPanel().ID(gridId);
        sharpDataList
            .Title(Model.PageTitle)
            .Store(x.StoreForModel().Listeners(li =>
            {
                li.Load.Fn = "storeLoad";
            }).Proxy(
    x.AjaxProxy().Url(Url.Action("GetPaged", new { userId = Request["userId"] })).Post().Reader(x.JsonReader().RootProperty("data"))).RemoteSort(true).RemotePaging(true).PageSize(25)
    .SorterFor(Model, m => m.Id, Ext.Net.SortDirection.DESC)
    )
    .SelectionModel(x.CheckboxSelectionModel())
    .ColumnModel(
    x.ColumnFor(m => m.Id),
    x.ColumnFor(m => m.Name),
    x.ColumnFor(m => m.Remark)
    )
    .BottomBar(x.PagingToolbar().ItemsFromPartial("~/Views/Shared/_PagingToolbarPartial.cshtml"))
    .EmptyText("无数据。")
    .View(x.GridView().StripeRows(true).TrackOver(true)).SharpReconfigure(Model).ResponsiveConfig();
    }
    @(sharpDataList)
}
